﻿@model Wheeler.Web.ViewModels.TestResultViewModel
@using Wheeler.Common.Extensions;
@using Wheeler.Web.Utility;
@using System.Text;
@{    
    //App.Web.ViewModels.ProductViewModel model = (App.Web.ViewModels.ProductViewModel)ViewBag.Product;
    Wheeler.Web.ViewModels.ZGL.Category.Category categoryLGL = null;

    if (Model != null && Model.CategoryZGL != null)
    {
        categoryLGL = Model.CategoryZGL;
    }
    String _Prefix = AppConstants.UI.DYNAMIC_CONTROL_PREFIX;
}
@functions{
    #region Like the Details ZGL Immplementation

    /// <summary>
    /// Creates a HTML bulleted list by separating the text with new line
    /// </summary>
    /// <param name="text"></param>
    /// <returns></returns>
    public String BuildBulletedList(String text, bool addUlTag = true)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder(10);
        if (!text.IsNullOrEmpty())
        {
            List<String> lines = new List<String>();
            if (text.IndexOf("\r\n") > -1)
                lines = text.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            else if (text.IndexOf("\n") > -1)
                lines = text.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            else
                lines = text.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
            if (lines.Count > 0)
            {
                if (addUlTag)
                    sb.Append("<ul>");
                foreach (String line in lines)
                {
                    if (!line.Trim().IsNullOrEmpty())
                        sb.AppendFormat("<li>{0}</li>", line.HtmlEncode());
                }
                if (addUlTag)
                    sb.Append("<ul>");
            }
            return sb.ToString();
        }
        return "N/A";//String.Empty;
    }
    /// <summary>
    /// Creates a HTML Bulleted List from the collection of generic objects
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public String BuildBulletedList(IList<Wheeler.Web.ViewModels.GenericViewModel> list)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder(10);
        if (list != null && list.Count > 0)
        {
            Wheeler.Web.ViewModels.GenericViewModel otherModel = list.FirstOrDefault(P => P.ID == null);
            if (otherModel != null)
                list.Remove(otherModel);
            sb.Append("<ul>");
            foreach (var item in list)
            {
                sb.AppendFormat("<li>{0}</li>", item.Name.HtmlEncode());
            }
            if (otherModel != null)
                sb.Append(BuildBulletedList(otherModel.Name, false));
            sb.Append("</ul>");
        }
        return sb.ToString();
    }

    public String BuildZGLProperties(Wheeler.Web.ViewModels.ZGL.Category.Category categoryZGL)
    {
        if (categoryZGL != null)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(10);
            foreach (Wheeler.Web.ViewModels.ZGL.Category.ProductGroup group in categoryZGL.Group)
            {   
                sb.AppendFormat("<div class='jb-group-title'>{0}</div>", group.Name);
                sb.Append("<ul>");
                foreach (Wheeler.Web.ViewModels.ZGL.Category.ProductGroupProperty property in group.Property)
                {
                    sb.Append(BuildBulletedList(String.Format("{0}: {1}", property.Label, property.Value.HtmlDecode()), false));
                }
                sb.Append("</ul>");
            }
            return sb.ToString();
        }
        return String.Empty;
    }

    #endregion Like the Details ZGL Implementation
}

@MvcHtmlString.Create(BuildZGLProperties(Model.CategoryZGL))

